package ACWing.TheNnderlyingAlgorithm.归并;
//788. 逆序对的数量

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/11/17 13:37
 */
public class TheNumberOFPairsINReverseOrder {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[]arr=new int[n];

        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        long sort = sort(arr, 0, n - 1);
        System.out.println(sort);
    }

    private static long sort(int[] arr, int l, int r) {
        if(l>=r){
            return 0;
        }
        int mid=l+r>>1;
        Long sum=sort(arr,l,mid)+sort(arr,mid+1,r);
        int k=0,i=l,j=mid+1,x=0;
        int[]temp=new int[r-l+1];
        while (i<=mid&&j<=r){
            if(arr[i]<=arr[j]){//左边小于右边不算逆序
                temp[k++]=arr[i++];
            }else {
                temp[k++]=arr[j++];
                x=x+mid-i+1;
            }
        }
        while (i<=mid){
            temp[k++]=arr[i++];
        }while (j<=r){
            temp[k++]=arr[j++];
        }
        for (int m = l,p=0; m <=r ; m++,p++) {
            arr[m]=temp[p];

        }
        return x+sum;
    }
}
